package cn.wolfcode.trip.admin.controller;


/**
 * Created by 13925 on 2018/10/29.
 */

import cn.wolfcode.trip.admin.util.UploadUtil;
import cn.wolfcode.trip.base.domain.Region;
import cn.wolfcode.trip.base.domain.TravelCommend;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.TravelCommendQuery;
import cn.wolfcode.trip.base.query.TravelQuery;
import cn.wolfcode.trip.base.service.IRegionService;
import cn.wolfcode.trip.base.service.ITravelCommendService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 游记推荐管理层
 */
@Controller
@RequestMapping("/travelCommend")
public class TravelCommendController {

    @Autowired
    private ITravelCommendService travelCommendService;

    @RequestMapping("/list")
    public String list(@ModelAttribute("qo") TravelCommendQuery qo, Model model) {
        qo.setOrderBy("schedule DESC");
        PageInfo result = travelCommendService.query(qo);
        model.addAttribute("result", result);
        return "travelCommend/list";
    }

    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(MultipartFile file, TravelCommend travelCommend) {
        //如果选择添加或者编辑文件
        if (file != null && file.getSize() > 0) {
            //文件上传
            String coverUrl = UploadUtil.upload(file, UploadUtil.BASE_IMAGE_PATH + "/upload");
            travelCommend.setCoverUrl(coverUrl);
        }
        travelCommendService.saveOrUpdate(travelCommend);
        return "redirect:/travelCommend/list.do";
    }

}
